package com.lzw.mapper.admin;

import com.lzw.pojo.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentManagementMapper {

    //根据条件查询学生信息
    List<Student> listStudents(@Param("name") String name, @Param("gender") String gender, @Param("phone") String phone);

    //查看名字是否存在
    @Select("SELECT COUNT(*) FROM dormitorymanagement.student WHERE name = #{name}")
    int countByName(String name);

    //查看用户名是否存在
    @Select("SELECT COUNT(*) FROM dormitorymanagement.student WHERE username = #{username}")
    int countByUsername(String username);

    //查看电话是否存在
    @Select("SELECT COUNT(*) FROM dormitorymanagement.student WHERE phone = #{phone}")
    int countByPhone(String phone);

    //添加学生
    @Insert("INSERT INTO dormitorymanagement.student(name, username, password, gender, phone, email, dormitory_id, building_id, image)" +
            "VALUES (#{name}, #{username}, #{password}, #{gender}, #{phone}, #{email}, #{dormitoryId}, #{buildingId}, #{image})")
    void addStudent(Student student);

    //删除学生
    void deleteStudent(@Param("ids") List<Integer> ids);

    //更新学生信息
    void updateStudent(Student student);

    //根据id查询学生信息
    @Select("SELECT * FROM dormitorymanagement.student WHERE student_id = #{studentId}")
    Student getStudentById(int id);

    //根据宿舍ID删除学生
    void deleteByDormitoryId(@Param("ids") List<Integer> ids);

    //根据楼宇ID删除学生
    void deleteByBuildingById(@Param("ids") List<Integer> ids);
}
